package com.anlu.yue.utils;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.HashMap;
import java.util.Map;

public class TransmittableThreadManager {
    
	private static TransmittableThreadLocal<Map<String, Object>> pool = new TransmittableThreadLocal<Map<String, Object>>();

	public static void put(String key, Object value) {
		if (pool.get() == null) {
			pool.set(new HashMap());
		}
		Map map = (Map) pool.get();
		map.put(key, value);
	}

	public static Object get(String key) {
		Map map = (Map) pool.get();
		if (map == null) {
			return null;
		}
		return map.get(key);
	}
	
	public static Object remove(String key){
		Map map = (Map) pool.get();
		if (map == null) {
			return null;
		}
		return map.remove(key);
	}

	public static Map getMap() {
		return ((Map) pool.get());
	}

	public static void clear() {
		pool.set(null);
	}
}
